/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.
 */
package com.ce.pms.charge.dao.impl;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.Query;

import com.ce.pms.base.dao.impl.PmsBaseDaoImpl;
import com.ce.pms.base.vo.SearchVO;
import com.ce.pms.charge.dao.INoteDao;
import com.ce.pms.charge.model.NoteDomain;
import com.ce.pms.charge.model.PeriodDomain;
import com.ce.pms.charge.vo.ManageHouseBankBean;
import com.ce.pms.charge.vo.NoteVO;
import com.ce.pms.charge.vo.TransRNoteVO;
import com.ce.pms.charge.vo.TransrnoteNote;
import com.ce.pms.common.annotation.AssociatedBuildingQuery;
import com.ce.pms.common.annotation.AssociatedPrecinctQuery;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.common.util.SqlConfig;
import com.ce.pms.report.vo.PrintChargeNoteBean;
import com.ce.util.DateUtil;
import com.sitechasia.webx.core.support.Page;

/**
 * 功能描述：通知单<br>
 * @author 罗军林 创建日期：2008-9-17
 */
public class NoteDaoImpl extends PmsBaseDaoImpl<NoteDomain> implements INoteDao {
	private SqlConfig sqlConfig=null;
	private final String SQLFILENAME="NoteSQL.xml";
	private final String CHECK_IS_BUILD_NOTE="checkIsBuildNote";
	private final String QUERY_PRECHINCT_HQL="queryPrechinctHQL";
	private final String QUERY_MANAGE_HOUSE="queryManageHouse";
	private final String QUERY_TRAN="queryTran";
	private final String INSERT_TRANS_R_NOTE="insertTransRNote";
	private final String QUERY_MANGE_ACCNUMBER="queryManageAccNumber";
	private final String INSERT_NOTE="insertNote";
	private final String CHECK_IS_RE_BUILD="checkIsReBuild";
	private final String QUERY_HOUSEIDS="queryHouseIds";
	private final String BLANK_OUT_NOTE="blankOutNote";
	private final String BLANK_OUT_NOTE_ALL="blankOutNoteAll";
	private final String CHECK_IS_RE_BUILD_ALL="checkIsReBuildAll";
	private final String QUERY_IS_BUILD_PERIOD_HQL="queryIsBuildPeriodHQL";
	private final String QUERY_PRINT_CHARGE_NOTE="queryPrintChargeNote";



	public NoteDaoImpl(){
		sqlConfig=new SqlConfig(SQLFILENAME);
	}
	@AssociatedPrecinctQuery(alias="note", beginStr=" and ", endStr=" ", insertAfterPoint="WHERE 1=1",property4Precinct="chargePrecint.keyword")
	public Page queryNote(NoteVO searchVO){
		Map<String, Object> paremeter=new HashMap<String, Object>();
		StringBuffer sql=new StringBuffer();
		sql.append("select note FROM NoteDomain note left join note.house.building hb WHERE 1=1")
		.append(buildCondition(searchVO, paremeter))
		.append(buildOrderStr(searchVO));

		return this.pagedNameQueryByPageNo(sql.toString(), searchVO.getPageNo(), searchVO.getPageSize(),paremeter);
	}

	private String buildOrderStr(SearchVO order){
		StringBuilder result=new StringBuilder(" order by ");
		if(null==order.getOrderValue() || order.getOrderValue().trim().length()==0 || "buildingName".equalsIgnoreCase(order.getOrderValue())){
			result.append(" note.house.building.seqNo " );
			result.append(order.getOrderKey());
		}else if("houseName".equalsIgnoreCase(order.getOrderValue()) ){
			if("desc".equalsIgnoreCase(order.getOrderKey())){
				result.append(" note.house.building.seqNo DESC,note.house.houseGrp DESC,note.house.floor DESC, note.house.houseNumber DESC ");
			}else{
				result.append(" note.house.building.seqNo,note.house.houseGrp,note.house.floor, note.house.houseNumber ");
			}
		}else{
			return "";
		}
		return result.toString();
	}


	public Page queryTransRNoteByNoteId(NoteVO notevo){
		String sql="FROM TransRNote tran WHERE tran.note.noteId=?";
		return pagedQueryByPageNo(sql, notevo.getPageNo(), notevo.getPageSize(), new Object[]{notevo.getNoteId()});
	}

	/**
	 * 功能描述:查询打印通知单<br>
	 * @param periodId
	 * @param noteId
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-10-9<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	@AssociatedPrecinctQuery(alias = "P", beginStr = " AND ", endStr = " ", insertAfterPoint = "WHERE 2=2",property4Precinct="CHARGE_PRECINCT_ID")
	public List<PrintChargeNoteBean> queryPrintChargeNote(NoteVO searchVO){
		String sql=sqlConfig.getSql(QUERY_PRINT_CHARGE_NOTE);
		List<Object> parameter=new ArrayList<Object>();
		sql = sql.replaceAll("_isReminder", searchVO.getReminder());
		sql=sql.replaceAll("_otherContion", buildCondtion(searchVO, parameter));
		Query query=createSQLQuery(sql, parameter.toArray());
		List<Object[]> result = query.list();
		return convertPrintNoteArrayToBean(result);
	}
	/** 功能描述:<br>
	 * @param searchVO
	 * @param parameter
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-10-9<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private String buildCondtion(NoteVO searchVO, List<Object> parameter) {
		StringBuffer otherContion=new StringBuffer();
		if(null != searchVO.getHouseIds() && searchVO.getHouseIds().trim().length()>0){
			otherContion.append(" AND H.HOUSE_ID IN ( ").append(searchVO.getHouseIds()).append(" ) ");
		}
		if(null != searchVO.getIsVirtualHouse()){
			otherContion.append(" AND H.IS_VIRTUAL = ? ");
			parameter.add(searchVO.getIsVirtualHouse());
		}
		if(null != searchVO.getBuildingId()){
			otherContion.append(" AND B.BUILDING_ID = ? ");
			parameter.add(searchVO.getBuildingId());
		}
		if(null != searchVO.getHouseName() && searchVO.getHouseName().trim().length()>0){
			otherContion.append(" AND H.HOUSE_NUMBER LIKE ? ");
			parameter.add("%"+searchVO.getHouseName()+"%");
		}
		if(null != searchVO.getPeriodId()){
			otherContion.append(" AND P.PERIOD_ID = ? ");
			parameter.add(searchVO.getPeriodId());
		}
		if(null != searchVO.getRequisitionNum() && searchVO.getRequisitionNum().trim().length()>0){
			otherContion.append(" AND NT.REQUISITION_NUM LIKE ?  ");
			parameter.add("%"+searchVO.getRequisitionNum()+"%");
		}
		if(null != searchVO.getValidity()){
			otherContion.append(" AND NT.VALIDITY = ? ");
			parameter.add(searchVO.getValidity());
		}
		if(null != searchVO.getNoteId()){
			otherContion.append(" AND NT.NOTE_ID = ? ");
			parameter.add(searchVO.getNoteId());
		}
		if(null != searchVO.getBuildDate()){
			otherContion.append(" AND NT.SYSDATE >= ? AND NT.SYSDATE< ?");
			Date beginDate =  DateUtil.clearFromHoursToMillis(searchVO.getBuildDate());
			parameter.add(beginDate);
			Date endDate = DateUtil.addDate(beginDate, 1);
			parameter.add(DateUtil.clearFromHoursToMillis(endDate));
		}
		return otherContion.toString();
	}
	/** 功能描述:<br>
	 * @param result
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-10-9<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private List<PrintChargeNoteBean> convertPrintNoteArrayToBean(List<Object[]> result) {
		List<PrintChargeNoteBean> temp=new ArrayList<PrintChargeNoteBean>();
		for(Object[] item : result){
			PrintChargeNoteBean printChargeNoteBean=new PrintChargeNoteBean();
			printChargeNoteBean.setHouseNumber( (String)item[0] );
			printChargeNoteBean.setParticipantName( (String)item[1] );
			printChargeNoteBean.setBuildSize( (BigDecimal)item[2] );
			printChargeNoteBean.setReceivableThisTotal( (BigDecimal)item[3] );
			printChargeNoteBean.setReceivableOldTotal( (BigDecimal)item[4] );
			printChargeNoteBean.setReceivableTotal( (BigDecimal)item[5] );
			printChargeNoteBean.setVoucherDate( (String)item[6] );
			printChargeNoteBean.setChargeItem( (String)item[7] );
			printChargeNoteBean.setThisAmt( (BigDecimal)item[8] );
			printChargeNoteBean.setOldAmt( (BigDecimal)item[9] );
			printChargeNoteBean.setThisTotalAmt( (BigDecimal)item[10] );
			printChargeNoteBean.setLastReading((BigDecimal)item[11]);
			printChargeNoteBean.setThisReading( (BigDecimal)item[12] );
			printChargeNoteBean.setDosage( (BigDecimal)item[13] );
			printChargeNoteBean.setPrice((BigDecimal)item[14]);
			printChargeNoteBean.setPrice1((BigDecimal)item[15]);
			printChargeNoteBean.setPrice2((BigDecimal)item[16]);
			printChargeNoteBean.setNoteId( ((BigInteger)item[17]).longValue() );

			temp.add(printChargeNoteBean);
		}
		return temp;
	}
	public static void main(String[] args) {
		System.out.println((String)null);
	}

	/**
	 * 功能描述:判断生成通知单的条件是否满足,如果可以生成，返回true<br>
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-18<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public boolean checkIsBuildNote(){
		Query query=this.createSQLQuery(sqlConfig.getSql(CHECK_IS_BUILD_NOTE), null);
		Object result=query.uniqueResult();
		return "0".equals(String.valueOf(result));
	}

	/**
	 * 功能描述:读取满足生成通知单条件的管理区(用户有权限生成通知单，已做应收计算且未生成通知单，全部数据已计算的所有管理区)<br>
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-18<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public List<PeriodDomain> queryPrechinct(){
		Query query=this.createQuery(sqlConfig.getSql(QUERY_PRECHINCT_HQL), null);
		return query.list();
	}

	/**
	 * 功能描述:读取满足生成通知单条件的管理区(用户有权限生成通知单，已生成通知单，全部数据已计算的所有管理区)<br>
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-18<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	@AssociatedBuildingQuery(alias="p", beginStr=" and ", endStr=" ", insertAfterPoint="WHERE 2=2",property4Building="chargePrecinct.keyword")
	public List<PeriodDomain> queryIsBuildPeriodHQL(){
		Query query=this.createQuery(sqlConfig.getSql(QUERY_IS_BUILD_PERIOD_HQL), null);
		return query.list();
	}

	/**
	 * 功能描述:查询指定管理区下的所有管理房-产权房关系<br>
	 * @param prechinctId 收费管理区ID
	 * @return key:产权房ID value:管理房ID<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-18<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public Map<Long,Long> queryManageHouse(Long prechinctId){
		Query query=this.createSQLQuery(sqlConfig.getSql(QUERY_MANAGE_HOUSE), prechinctId);
		Map<Long,Long> result=new HashMap<Long, Long>();
		List<Object[]> list=query.list();
		for(Object[] item : list){
			result.put( ((BigInteger)item[1]).longValue(), ((BigInteger)item[0]).longValue());
		}
		return result;
	}

	/**
	 * 功能描述:查询交易(读取这些楼栋对应的产权房，及相关的交易，按房屋、交易码分组统计应收金额，
	 * 去除应收总额为0的收费项目，查询相关的银行账号。<br>
	 * @param periodId<br>
	 * @param prechinctId<br>
	 * @param pageNO<br>
	 * @param pageSize<br>
	 * @return <br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-18<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public List<TransrnoteNote> queryTran(Long periodId,Long prechinctId,String houseIds,int pageNO,int pageSize){
		String sql = buildConditionByHouseIds(houseIds);
		int startRow=(pageNO-1) * pageSize;
		Query query=this.createSQLQuery(sql,
				periodId,periodId,prechinctId,prechinctId,periodId,periodId,prechinctId,startRow,pageSize);
		List<Object[]> list=query.list();

		List<TransrnoteNote> temp=new ArrayList<TransrnoteNote>();
		for(Object[] item : list){
			TransrnoteNote transrnoteNote=new TransrnoteNote();
			transrnoteNote.setChargeItemId( item[0]==null ? null : ((BigInteger)item[0]).longValue() );
			transrnoteNote.setHouseId( ((BigInteger)item[1]).longValue() );
			transrnoteNote.setHouseNumber( String.valueOf(item[2]) );
			transrnoteNote.setBuildSize( (BigDecimal)item[3] );
			transrnoteNote.setThisAmt( (BigDecimal)item[4] );
			transrnoteNote.setOldAmt( (BigDecimal)item[5] );
			transrnoteNote.setTotalAmt( (BigDecimal)item[6] );
			transrnoteNote.setProRightId( ((BigInteger)item[7]).longValue() );
			transrnoteNote.setClients( String.valueOf(item[8]) );
			temp.add(transrnoteNote);
		}
		return temp;
	}
	/**
	 * 功能描述:<br>
	 * @param houseIds
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-25<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private String buildConditionByHouseIds(String houseIds) {
		String sql=sqlConfig.getSql(QUERY_TRAN);
		if(houseIds==null || houseIds.trim().length()<1){
			sql=sql.replace("_otherSearchCondition", "");
		}else{
			sql=sql.replace("_otherSearchCondition", " AND H.HOUSE_ID IN ( "+houseIds+" ) ");
		}
		return sql;
	}

	/**
	 * 功能描述:取得当前拥有通知单的数量<br>
	 * @param periodId
	 * @param isReminder 是否为催缴单
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-19<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public int getCountNote(Long periodId ,boolean isReminder){
		String hql= "SELECT COUNT(note) FROM NoteDomain note WHERE note.period.keyword=? AND note.reminder= ?";
		String reminder = isReminder == true ?"1":"0";
		Query query=createQuery(hql, new Object[]{periodId,reminder});
		return ((Long)query.uniqueResult()).intValue();
	}

	/**
	 * 功能描述:查询指定管理区下的所有管理房银行帐号。key 管理房ID，value 银行帐号<br>
	 * @param precinctId
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-23<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public Map<Long,ManageHouseBankBean> queryManageAccNumber(){
		Query query=createSQLQuery(sqlConfig.getSql(QUERY_MANGE_ACCNUMBER), null);
		List<Object[]> list= query.list();
		Map<Long, ManageHouseBankBean> result=new HashMap<Long, ManageHouseBankBean>();
		for(Object[] item : list){
			ManageHouseBankBean manageHouseBankBean=new ManageHouseBankBean();
			manageHouseBankBean.setManageHouseId( ((BigInteger)item[0]).longValue() );
			manageHouseBankBean.setAccNumber( item[1]==null ? null : (String)item[1] );
			manageHouseBankBean.setHouseNumber( item[2]==null ? null : (String)item[2] );
			manageHouseBankBean.setProRightId( ((BigInteger)item[3]).longValue() );
			manageHouseBankBean.setClients( item[4]==null ? null : (String)item[4] );
			result.put( manageHouseBankBean.getManageHouseId() ,  manageHouseBankBean);
		}
		return result;
	}

	/**
	 * 功能描述:批量插入通知单明细<br>
	 * @param transNoteList<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-22<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void insertTransRNote(List<TransRNoteVO> transNoteList){
		List<Object[]> list=new ArrayList<Object[]>();
		for(TransRNoteVO transNote : transNoteList){
			Object[] parameter=new Object[]{
					transNote.getNoteId(),
					transNote.getChargeItemId(),
					transNote.getLastReading(),
					transNote.getThisReading(),
					transNote.getOldAmt(),
					transNote.getThisAmt(),
					transNote.getTotalAmt(),
					transNote.getWastage(),
					transNote.getPrice(),
					transNote.getOverPrice1(),
					transNote.getOverPrice2()
			};
			list.add(parameter);
		}
		executeSQLBatch(sqlConfig.getSql(INSERT_TRANS_R_NOTE), list);
	}

	/**
	 * 功能描述:批量插入通知单<br>
	 * @param userId
	 * @param manageHouseTransrnoteNoteMap<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-23<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void insertNote(Long userId,Map<Long,TransrnoteNote> manageHouseTransrnoteNoteMap){
		List<Object[]> list=new ArrayList<Object[]>();
		for(TransrnoteNote item : manageHouseTransrnoteNoteMap.values()){
			Object[] parameter=new Object[]{
					item.getChargePrecinctId(),
					item.getHouseId(),
					item.getProRightId(),
					item.getHouseNumber(),
					item.getClients(),
					item.getBuildSize(),
					item.getRequistionNum(),
					item.getAccNumber(),
					item.getPeriodId(),
					item.getThisAmt(),
					item.getOldAmt(),
					item.getTotalAmt(),
					SysrefcodeDO.FEE_NOTE_REMINDER_FALSE,
					userId,
					SysrefcodeDO.FEE_NOTE_VALIDITY_TRUE
			};
			list.add(parameter);
		}
		executeSQLBatch(sqlConfig.getSql(INSERT_NOTE), list);
	}

	/**
	 * 功能描述:检查能否重新生成通知单<br>
	 * @param houseIds
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-24<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public boolean checkIsReBuild(String houseIds){
		String sql=sqlConfig.getSql(CHECK_IS_RE_BUILD).replaceAll("_houseIds", houseIds);
		Query query=this.createSQLQuery(sql, null);
		Object result=query.uniqueResult();
		return "0".equals(String.valueOf(result));
	}

	/**
	 * 功能描述:检查能否重新生成全部通知单<br>
	 * @return<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-24<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public boolean checkIsReBuildAll(){
		Query query=this.createSQLQuery(sqlConfig.getSql(CHECK_IS_RE_BUILD_ALL), null);
		Object result=query.uniqueResult();
		return "0".equals(String.valueOf(result));
	}

	/**
	 * 功能描述:查询所选房间所属的收费周期及其相关产权房ID<br>
	 * @param houseIds 房号ID列表，管理房、产权房ID都可以
	 * @return key：收费周期ID value:房号id列表<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-24<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	@AssociatedBuildingQuery(alias="H", beginStr=" AND ", endStr=" ", insertAfterPoint="WHERE 2=2",property4Building="BUILDING_ID")
	public Map<Long,String> queryPeriodHouseIds(String houseIds){
		String sql=sqlConfig.getSql(QUERY_HOUSEIDS).replaceAll("_houseIds", houseIds);
		Query query=this.createSQLQuery(sql, null);
		List<Object[]> list=query.list();

		Map<Long,String> result=new HashMap<Long, String>();
		for(Object[] item : list){
			Long periodId=((BigInteger)item[1]).longValue();
			String hids=(item[2]==null ? null : (String)item[2]);
			result.put(periodId, hids);
		}
		return result;
	}

	/**
	 * 功能描述:作废指定收费周期指定房号的通知单<br>
	 * @param periodId
	 * @param preinctId
	 * @param houseIds 房号ID列表，管理房、产权房ID都可以
	 * Create author:罗军林<br>
	 * Create on:2008-9-24<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void blankOutNote(Long periodId,Long preinctId,String houseIds){
		String sql=sqlConfig.getSql(BLANK_OUT_NOTE).replaceAll("_houseIds", houseIds);
		Query query=this.createSQLQuery(sql, preinctId,periodId);
		query.executeUpdate();
	}

	/**
	 * 功能描述:作废指定收费周期下的所有通知单<br>
	 * @param periodId
	 * Create author:罗军林<br>
	 * Create on:2008-9-24<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public void blankOutNoteAll(Long periodId){
		Query query=this.createSQLQuery(sqlConfig.getSql(BLANK_OUT_NOTE_ALL), periodId);
		query.executeUpdate();
	}

	/**
	 * 功能描述:<br>
	 * @param searchCondition
	 * @param paremeter
	 * @param hql<br>
	 * Create author:罗军林<br>
	 * Create on:2008-9-11<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	private String buildCondition(NoteVO searchCondition, Map<String, Object> paremeter) {
		StringBuffer hql=new StringBuffer();
		if(null != searchCondition.getHouseId()){
			hql.append(" AND note.house.keyword=:houseId");
			paremeter.put("houseId", searchCondition.getHouseId());
		}

		if(null != searchCondition.getIsVirtualHouse() && searchCondition.getIsVirtualHouse().trim().length()>0){
			hql.append(" AND note.house.isVirtual=:isVirtualHouse");
			paremeter.put("isVirtualHouse", searchCondition.getIsVirtualHouse());
		}

		if(null != searchCondition.getHouseIds() && searchCondition.getHouseIds().trim().length()>0){
			hql.append(" AND note.house.keyword in (").append(searchCondition.getHouseIds()).append(") ");
		}

		if(null != searchCondition.getBuildingId()){
			hql.append(" AND note.house.building.keyword=:buildingId");
			paremeter.put("buildingId", searchCondition.getBuildingId());
		}

		if(null != searchCondition.getHouseName() && searchCondition.getHouseName().trim().length()>0){
			hql.append(" AND note.houseNumber like :houseNumber");
			paremeter.put("houseNumber", "%"+searchCondition.getHouseName()+"%");
		}

		if(null != searchCondition.getPeriodId()){
			hql.append(" AND note.period.keyword=:periodId");
			paremeter.put("periodId", searchCondition.getPeriodId());
		}

		if(null != searchCondition.getRequisitionNum() && searchCondition.getRequisitionNum().trim().length()>0){
			hql.append(" AND note.requisitionNum like :requisitionNum");
			paremeter.put("requisitionNum", "%"+searchCondition.getRequisitionNum()+"%");
		}

		if(null != searchCondition.getValidity()){
			hql.append(" AND note.validity=:validity");
			paremeter.put("validity", searchCondition.getValidity());
		}

		if(null != searchCondition.getProRightIds() && searchCondition.getProRightIds().trim().length()>0){
			hql.append(" AND note.proRight.proRightId in ( ")
			.append(searchCondition.getProRightIds())
			.append(" )") ;
		}

		//是否是否催缴单
		if(null != searchCondition.getReminder()){
			hql.append(" AND note.reminder=:reminder");
			paremeter.put("reminder", searchCondition.getReminder());
		}
		//生成日期
		if(null != searchCondition.getBuildDate()){
			hql.append(" AND note.sysInfo.sysDate >=:beginDate and note.sysInfo.sysDate <:endDate ");
			Date beginDate =  DateUtil.clearFromHoursToMillis(searchCondition.getBuildDate());
			paremeter.put("beginDate",beginDate);
			Date endDate = DateUtil.addDate(beginDate, 1);
			paremeter.put("endDate", DateUtil.clearFromHoursToMillis(endDate));
		}

		return hql.toString();
	}
}
